<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>WiFi Logger component: WiFi Logger component</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">WiFi Logger component
   &#160;<span id="projectnumber">1.0</span>
   </div>
   <div id="projectbrief">WiFi Logger component, uses wifi to output logs</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">WiFi Logger component </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>ESP32 WiFi logger - Log messages over WiFi, using either TCP, UDP or Websockets</p><ul>
<li>Generates log messages with same format as ESP-IDF Logging API</li>
<li>Follows ESP-IDF color pattern for different log levels.</li>
<li>Using UDP as network protocol provides lowest latency<ul>
<li>Minimal test condition - minimum free heap = 220388 bytes</li>
</ul>
</li>
<li>TCP performance is mid-way<ul>
<li>Minimal test condition - minimum free heap = 216537 bytes</li>
</ul>
</li>
<li>Using Websockets provides the worst latency<ul>
<li>Minimal test condition - minimum free heap = 205416 bytes</li>
</ul>
</li>
</ul>
<h2>Requirements</h2>
<ul>
<li><code>protocol_examples_common (esp-idf/examples/common_components/)</code></li>
</ul>
<h2>Installation</h2>
<div class="fragment"><div class="line">cd &lt;your_esp_idf_project&gt;</div><div class="line">mkdir components</div><div class="line">cd components</div><div class="line">cp $IDF_PATH/examples/common_components/protocol_examples_common . -r</div><div class="line">git clone https://github.com/VedantParanjape/esp-wifi-logger.git wifi_logger</div></div><!-- fragment --><p>Change CMakeList.txt to add the line given below:</p>
<p><code>set(EXTRA_COMPONENT_DIRS &lt;relative_path_to_component_folder&gt;)</code></p>
<p>component folder must contain <code>protocol_examples_common</code> and <code>wifi_logger</code> component </p><h2>Usage</h2>
<h3>How to receive logs</h3>
<ul>
<li><code>sudo apt-get install netcat</code> Netcat is required to receive logs</li>
<li><code>nc -lu &lt;PORT&gt;</code> Receive logs when <em><b>udp</b></em> is used as network protocol</li>
<li><code>nc -l &lt;PORT&gt;</code> Receive logs when <em><b>tcp</b></em> is used as network protocol</li>
<li><code>websocat -s &lt;IP_ADDRESS_OF_YOUR_MACHINE&gt;:&lt;PORT&gt;</code> Receive logs when <em><b>websocket</b></em> is used as network protocol</li>
<li>`websocat -s $(ip -o route get to 8.8.8.8 | sed -n 's/.*src ([0-9.]+).*/\1/p'):1234` receive logs when <em><b>websocket</b></em> is used as network protocol, auto fills the ip address</li>
<li><b>Example</b>: Assume, <em>port</em> is <b>1212</b> over TCP, command will be: <code>nc -l 1212</code></li>
</ul>
<p>### How to use in ESP-IDF Projects </p><div class="fragment"><div class="line">wifi_log_e() - Generate log with log level ERROR</div><div class="line">wifi_log_w() - Generate log with log level WARN</div><div class="line">wifi_log_i() - Generate log with log level INFO</div><div class="line">wifi_log_d() - Generate log with log level DEBUG</div><div class="line">wifi_log_v() - Generate log with log level VERBOSE</div></div><!-- fragment --><ul>
<li>Usage pattern same as, <code>ESP_LOGX()</code></li>
<li>Use <code>wifi_log()_x</code> function to print logs over wifi</li>
<li>Example: <code>wifi_log(TAG, "%s", "logger test");</code></li>
<li>Call <code><a class="el" href="wifi__logger_8h.html#a8e612786031d82bb0eac8affe469ed2c" title="wrapper function to start wifi logger ">start_wifi_logger()</a></code> in <code>void app_main()</code> to start the logger. Logging function <code>wifi_log</code> can be called to log messages</li>
<li>Configure <code>menuconfig</code><ul>
<li><code>Example Connection Configuration</code> <em>Set WiFi SSID and password</em></li>
<li><code>Component config</code></li>
<li><code>WiFi Logger configuration</code><ul>
<li><code>Network Protocol (TCP/UDP/WEBSOCKET)</code> - Set network protocol to be used<ul>
<li><code>UDP/TCP Network Protocol</code><ul>
<li><code>Server IP Address</code> - Set the IP Address of the server which will receive log messages sent by ESP32</li>
<li><code>Port</code> - Set the Port of the server</li>
</ul>
</li>
<li><code>WEBSOCKET Network Protocol</code><ul>
<li><code>Websocket Server URI</code> - Sets the URI of Websocket server, where logs are to be sent</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><em>IP Address of the server can be found out by running <code>ifconfig</code> on a linux machine</em></p>
<h2>Configuration</h2>
<div class="fragment"><div class="line">idf.py menuconfig</div></div><!-- fragment --><ul>
<li><code>Example Connection Configuration</code><ul>
<li><code>WiFi SSID</code> - Set WiFi SSID to connect</li>
<li><code>WiFi Password</code> - Set WiFi Password</li>
</ul>
</li>
<li><code>Component config</code><ul>
<li><code>WiFi Logger configuration</code><ul>
<li><code>Network Protocol (TCP/UDP/WEBSOCKET)</code> - Set network protocol to be used<ul>
<li><code>UDP/TCP Network Protocol</code><ul>
<li><code>Server IP Address</code> - Set the IP Address of the server which will receive log messages sent by ESP32</li>
<li><code>Port</code> - Set the Port of the server</li>
</ul>
</li>
<li><code>WEBSOCKET Network Protocol</code><ul>
<li><code>Websocket Server URI</code> - Sets the URI of Websocket server, where logs are to be sent</li>
</ul>
</li>
</ul>
</li>
<li><code>Queue Size</code> - <em><b>Advanced Config, change at your own risk</b></em> Set the freeRTOS Queue size used to pass log messages to logger task.</li>
<li><code>logger buffer size</code> - <em><b>Advanced Config, change at your own risk</b></em> Set the buffer size of char array used to generate log messages in ESP format</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2>Example</h2>
<div class="fragment"><div class="line">#include &lt;stdio.h&gt;</div><div class="line">#include &quot;freertos/FreeRTOS.h&quot;</div><div class="line">#include &quot;freertos/task.h&quot;</div><div class="line">#include &quot;wifi_logger.h&quot;</div><div class="line"></div><div class="line"></div><div class="line">void app_main(void)</div><div class="line">{</div><div class="line">    start_wifi_logger(); // Start wifi logger</div><div class="line"></div><div class="line">    while(1)</div><div class="line">    {</div><div class="line">        wifi_log_e(&quot;test&quot;, &quot;%s %d %f&quot;, &quot;hello world wifi logger&quot;, 43, 45.341223242); // write log over wifi with log level -&gt; ERROR</div><div class="line">        wifi_log_w(&quot;test&quot;, &quot;%s %d %f&quot;, &quot;hello world wifi logger&quot;, 43, 45.341223242); // write log over wifi with log level -&gt; WARN</div><div class="line">        wifi_log_i(&quot;test&quot;, &quot;%s %d %f&quot;, &quot;hello world wifi logger&quot;, 43, 45.341223242); // write log over wifi with log level -&gt; INFO</div><div class="line">        wifi_log_d(&quot;test&quot;, &quot;%s %d %f&quot;, &quot;hello world wifi logger&quot;, 43, 45.341223242); // write log over wifi with log level -&gt; DEBUG</div><div class="line">        wifi_log_v(&quot;test&quot;, &quot;%s %d %f&quot;, &quot;hello world wifi logger&quot;, 43, 45.341223242); // write log over wifi with log level -&gt; VERBOSE</div><div class="line"></div><div class="line">        vTaskDelay(100);  // Wait for 100ms, prevent watchdog from triggering a reset</div><div class="line">    }</div><div class="line">}</div></div><!-- fragment --> </div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>
